{extend name='public/layout' /}
{block name='content'}
<style>
    .main{padding:10px;background-color: #fff;}
</style>
<div class="main ">
    <div class="ylj-box ylj-padding-t-b ylj-margin-b">
        <form action="{:url('regDo')}" method="post" id="form" class="am-form ylj-padding-l-r" >
            <div class="am-form-group am-form-icon">
                <i class="am-icon-user"></i>
                <input type="text" name="username" id="username" class="am-form-field" placeholder="用户名">
            </div>
            <div class="am-form-group am-form-icon">
                <i class="am-icon-phone"></i>
                <input type="text" name="mobile" id="mobile" class="am-form-field" placeholder="手机号码">
            </div>
            <div class="am-form-group am-form-icon">
                <i class="am-icon-envelope"></i>
                <input type="text" name="email" id="email" class="am-form-field" placeholder="邮箱号码">
            </div>
            <div class="am-form-group am-form-icon">
                <i class="am-icon-lock"></i>
                <input type="password" name="password" id="password" class="am-form-field" placeholder="密码">
            </div>
            <div class="am-form-group am-form-icon">
                <i class="am-icon-lock"></i>
                <input type="password" name="repassword" id="password2" class="am-form-field" placeholder="确认密码">
            </div>
            <div class="am-form-group am-form-icon">
                <i class="am-icon-image"></i>
                <input type="text" class="am-form-field" name="code" id="code" style="padding-right:140px;" placeholder="验证码">
                <img src="{:captcha_src()}" id="code_img" alt="" class="am-fr" style="position:absolute;top:0;right:2px;height:35px;">
            </div>
            <div class="am-form-group">
                <span>
                    <input type="checkbox" checked value="1" disabled><a href="{:url('Pages/detail@m',['alias'=>$oneCate['cate'][7]['alias']])}"  class="ylj-word-color">同意《{$site.title}用户协议》</a>
                </span>
                <span class="am-fr">已有账号 <a href="{:url('index')}" class=" ylj-word-color">立即登录</a></span>
            </div>
            <div class="am-form-group">
                <button type="button" id="ylj-sub-btn" class="am-btn ylj-btn-color am-btn-block am-round">注册</button>
            </div>
        </form>
    </div>

</div>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script src="__PUBLIC__/js/plugins/jquery.ajax.form.js"></script>
<script>
    $(function(){
        $("#code_img").click(function(){
            var timenow = new Date().getTime();
            $('#code_img').attr("src","{:captcha_src()}?t"+timenow)
        });
        $('#ylj-sub-btn').click(function(){
            var username   = $("#username").val();
            var mobile   = $('#mobile').val();
            var email    = $('#email').val();
            var password = $("#password").val();
            var password2 = $('#password2').val();
            var code     = $("#code").val();
            var reg      = /^1[34578][0-9]{9}$/;
            if(username.length == 0){
                layer.msg('请填写用户名',{icon:2});
                return false;
            }
            if(!reg.test(mobile)){
                layer.msg('请填写正确的手机号码',{icon:2});
                return false;
            }
            if(email.length == 0){
                layer.msg('请填写邮箱号码',{icon:2});
                return false;
            }
            if(password.length == 0){
                layer.msg('请填写密码',{icon:2});
                return false;
            }
            if(password!=password2){
                layer.msg('两次密码输入不一致',{icon:2});
                return false;
            }
            if(code.length == 0){
                layer.msg('请填写验证码',{icon:2});
                return false;
            }
            $('#form').submit();
        });
        $('#form').ajaxForm({success:complate,dataType:'json'});
        function complate(result){
            if(result.status == 1){
                window.location.href = result.uri;
            } else {
                layer.msg(result.msg,{icon:2});
            }
        }
    });
</script>
{/block}